package com.isdepci.project.gasEmission.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.project.gasEmission.domain.BusinessTravel;
import com.isdepci.project.gasEmission.service.IBusinessTravelService;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.web.page.TableDataInfo;

/**
 * 差旅Controller
 *
 * @author isdepci
 * @date 2023-09-01
 */
@RestController
@RequestMapping("/travel/travel")
public class BusinessTravelController extends BaseController
{
    @Autowired
    private IBusinessTravelService businessTravelService;

    /**
     * 查询差旅列表
     */
    @PreAuthorize("@ss.hasPermi('travel:travel:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessTravel businessTravel)
    {
        startPage();
        List<BusinessTravel> list = businessTravelService.selectBusinessTravelList(businessTravel);
        return getDataTable(list);
    }

    /**
     * 导出差旅列表
     */
    @PreAuthorize("@ss.hasPermi('travel:travel:export')")
    @Log(title = "差旅", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusinessTravel businessTravel)
    {
        List<BusinessTravel> list = businessTravelService.selectBusinessTravelList(businessTravel);
        ExcelUtil<BusinessTravel> util = new ExcelUtil<BusinessTravel>(BusinessTravel.class);
        return util.exportExcel(list, "travel");
    }

    /**
     * 获取差旅详细信息
     */
    @PreAuthorize("@ss.hasPermi('travel:travel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(businessTravelService.selectBusinessTravelById(id));
    }

    /**
     * 新增差旅
     */
    @PreAuthorize("@ss.hasPermi('travel:travel:add')")
    @Log(title = "差旅", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessTravel businessTravel)
    {
        return toAjax(businessTravelService.insertBusinessTravel(businessTravel));
    }

    /**
     * 修改差旅
     */
    @PreAuthorize("@ss.hasPermi('travel:travel:edit')")
    @Log(title = "差旅", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessTravel businessTravel)
    {
        return toAjax(businessTravelService.updateBusinessTravel(businessTravel));
    }

    /**
     * 删除差旅
     */
    @PreAuthorize("@ss.hasPermi('travel:travel:remove')")
    @Log(title = "差旅", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(businessTravelService.deleteBusinessTravelByIds(ids));
    }
}
